using System;
using System.Globalization;
using System.Threading;
using System.Web;
using Butterfly.Library.Utilities;
namespace Butterfly.Library
{
	public class HitCounterHttpModule:IHttpModule
	{
		private HttpApplication _application;
		public void Init(HttpApplication app)
		{
			this._application = app;
			this._application.BeginRequest += new EventHandler(_application_BeginRequest);
		}
		public void _application_BeginRequest(object sender, EventArgs e)
		{      

            //using isapi

            //string strPath = HttpContext.Current.Request.Url.AbsolutePath;
            //if (strPath.IndexOf("Modules") > 0) return;
            //if (strPath.IndexOf("images") > 0) return;
            //if (strPath.IndexOf("Images") > 0) return;
            //if (strPath.IndexOf("Style") > 0) return;
            //if (strPath.IndexOf("Jscripts") > 0) return;
            //if (strPath.IndexOf("RadControls") > 0) return;

            //UrlRedirection oPR = new UrlRedirection();

            //string strURL = "";

            //string strRewrite = oPR.GetMatchingRewrite(strPath);

            //if (!String.IsNullOrEmpty(strRewrite))
            //{
            //    strURL = strRewrite;
            //}
            //else
            //{
            //    strURL = strPath;
            //}

            int count = ConvertUtility.ToInt32(Components.Portal.PortalSetting.GetSetting()[Definition.Portal_Hit_Counter]);
            count++;
            Components.Portal.PortalSetting.SetValue(Definition.Portal_Hit_Counter, count.ToString());
            string langCulture = AppEnv.GetLanguage();
            CultureInfo cur = new CultureInfo(langCulture);
            Thread.CurrentThread.CurrentCulture = cur;
            Thread.CurrentThread.CurrentUICulture = cur;

            //HttpContext.Current.RewritePath("~" + strURL);
		}
		public void Dispose()
		{
			
		}
	}
}
